﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Expo.Training.Entity;

public partial class LearningMap_AddMap : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ED_Editor.Show();
            this.trLearnPlace.Visible = false;
        }
    }

    public void DoAdd(object sender, System.EventArgs e)
    {
        string description = ED_Editor.Content;
        Learning_Place place = new Learning_Place();
        try
        {
            if (string.IsNullOrEmpty(this.ddlPlace.SelectedItem.Text))
            {
                this.AddEndScript("error", "alert('请选择学习地点！');");
                return;
            }

            if (string.IsNullOrEmpty(txtLocalName.Text))
            {
                this.AddEndScript("error", "alert('请输入学习点名称！');");
                return;
            }

            if (string.IsNullOrEmpty(txtPageSite.Text))
            {
                this.AddEndScript("error", "alert('请输入学习点主页！');");
                return;
            }
            Guid localId = Guid.NewGuid();
            place.LocalID = localId;
            place.ParentID = ddlPlace.SelectedValue;
            place.ParentName= ddlPlace.SelectedItem.Text;
            if (rbType.SelectedValue.Equals("0"))
                place.LocalName = ddlPlace.SelectedItem.Text;
            else
                place.LocalName = txtLocalName.Text;
            place.LocalUrl = txtPageSite.Text;
            place.LearningType = int.Parse(this.rbType.SelectedValue);
            place.Description = description;
            place.ModifyBy = this.Member.MemberID;
            place.CreateBy = this.Member.MemberID;
            place.CreateDate = DateTime.Now;
            place.ModifyDate = DateTime.Now;
            if (place.Add())
            {
                Expo.Training.BRule.Audit.Audit.AuditLog(this.Member.MemberID, "添加-地图-ID：" + localId);
                Response.Redirect("Default.aspx");
            }
        }
        catch (Exception ex)
        {
            Expo.Training.BRule.Audit.Audit.AuditLog(this.Member.MemberID, "异常：" + ex.Message);
        }
        finally
        {
            place.Dispose();
        }
    }

    protected void rbType_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.rbType.SelectedValue.Equals("1"))
            this.trLearnPlace.Visible = true;
        else
            this.trLearnPlace.Visible = false;
    }
   
}
